package terra.model.effect;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;

import terra.Config;
import terra.model.GameObject;
import terra.model.MapObject;
import terra.slick.GameState;
import terra.util.FontUtils;

public class HitEffect extends AbstractEffect {

	int hit;
	byte isCrit = 0;
	int x,y,w,h,y1;
	boolean red = false;
	public HitEffect(GameObject obj, int hit,byte crit) {
		time = 3000;
		x = (int) obj.getX();
		y = (int) obj.getY();
		w = obj.getW();
		h = obj.getH();
		isCrit = crit;
		if (obj == GameState.getInstance().player)
			red = true;
		this.hit -= hit;
	}
	
	public HitEffect(MapObject obj, int damage)	{
		time = 2000;
		x = obj.x;
		y = obj.y;
		w = Config.tileSize;
		h = Config.tileSize;
		hit -= damage;
	}

	public void draw(Graphics g) {
		float alpha = 20f*((2000-time)/100f)/100f;
		alpha = 1-alpha;
		if (alpha > 1f)
			alpha = 1f;
		if (alpha < 0f)
			alpha = 0f;
		Color c;
		if (red)
			c = new Color(Color.red.getRed(),Color.red.getGreen(),Color.red.getBlue(),alpha*2);
		else
			c = new Color(Color.green.getRed(),Color.green.getGreen(),Color.green.getBlue(),alpha*2);
		FontUtils.drawCenter(GameState.font12, (isCrit == 1 ? "Crit! " : "")+String.valueOf(hit), x, y+y1-32, w, c);
		y-= 0.1f;
	}

	@Override
	public void end() {
		remove = true;
	}

}
